﻿<Window x:Class="ListOfTale.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Справочник сказок" Height="350" Width="700" Closing="Window_Closing" xmlns:my="clr-namespace:ListOfTale" Loaded="Window_Loaded" >
    <Window.Resources>
        <my:TalesDataSet x:Key="talesDataSet" />
        <CollectionViewSource x:Key="authorViewSource" Source="{Binding Path=Author, Source={StaticResource talesDataSet}}" />
        <CollectionViewSource x:Key="keysViewSource" Source="{Binding Path=Keys, Source={StaticResource talesDataSet}}" />
        <CollectionViewSource x:Key="tale_vViewSource" Source="{Binding Path=Tale_v, Source={StaticResource talesDataSet}}" />
        <CollectionViewSource x:Key="taleViewSource" Source="{Binding Path=Tale, Source={StaticResource talesDataSet}}" />
    </Window.Resources>
        <Grid Name="root" DataContext="{StaticResource taleViewSource}">
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="296*" />
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem Header="Справочники">                
                <MenuItem Click="MenuItem_Click" Header="таблица ключевых слов"></MenuItem>
                <MenuItem Header="таблица авторов" Click="MenuItem_Click_1"></MenuItem>
            </MenuItem>
            <MenuItem Header="Операции">
                <MenuItem Header="Экспортировать в word" Click="MenuItem_Click_2"></MenuItem>
                <!--<MenuItem Header="Импорт из word" Click="MenuItem_Click_5"></MenuItem>
                <MenuItem Header="Импорт из lox.txt" Click="MenuItem_Click_6"></MenuItem>-->
            </MenuItem>
            <MenuItem Header="Диаграммы">
                <MenuItem Header="Авторская и народная сказка по годам" Click="MenuItem_Click_3"></MenuItem>
                <MenuItem Header="Авторская и народная сказка. общее соотношение" Click="MenuItem_Click_4"></MenuItem>
            </MenuItem>
            <MenuItem Header="Помощь">
                <!--<MenuItem Header="Авторская и народная сказка по годам" Click="MenuItem_Click_3"></MenuItem>-->
                
                <MenuItem Header="О программе" Click="MenuItem_Click_8"></MenuItem>
            </MenuItem>
        </Menu>
        <WrapPanel VerticalAlignment="Top" HorizontalAlignment="Stretch" Orientation="Horizontal" Grid.RowSpan="2" Grid.Row="1">
            <Label >
                Название
            </Label>
            <TextBox x:Name="NameTale" Width="50"  KeyboardNavigation.TabIndex="0"/>
            <Label>
                Год
            </Label>
            <TextBox x:Name="Year" Width="50"  KeyboardNavigation.TabIndex="1"/>
            <Label>
                Тираж
            </Label>
            <TextBox x:Name="Printing" MinWidth="100"  KeyboardNavigation.TabIndex="2"/>

            <Button Click="Button_Click_1">
                Загрузить первые сказки
            </Button>
            <Button Click="Button_Click_2">
                Загрузить все сказки
            </Button>
        </WrapPanel>
        <StackPanel Orientation="Horizontal" Grid.Row="2">
            <Grid DataContext="{StaticResource authorViewSource}"  HorizontalAlignment="Left"  Name="grid1" VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Content="Автор:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center"/>
                <ComboBox  KeyboardNavigation.TabIndex="3" DisplayMemberPath="Name" SelectedIndex="0" IsEditable="True" SelectedValue="AuthorId" Grid.Column="1" IsTextSearchEnabled="True"  Grid.Row="0" Height="23" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="3" Name="AuthComb" VerticalAlignment="Center" Width="120">
                <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ComboBox.ItemsPanel>
            </ComboBox>
        </Grid>
        <Grid DataContext="{StaticResource keysViewSource}" Name="grid2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Content="Ключевое слово:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                <ComboBox DisplayMemberPath="Name"  KeyboardNavigation.TabIndex="4" IsEditable="True" Grid.Column="1" Grid.Row="0" IsTextSearchEnabled="True" Height="23" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="3" Name="keyComb" VerticalAlignment="Center" Width="120">
                <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ComboBox.ItemsPanel>
            </ComboBox>
        </Grid>
            <Button  Width="75" Content="Добавить" Click="Addbtn_Click"  KeyboardNavigation.TabIndex="5"/>
            <Button  Width="75" Content="Удалить" Click="Button_Click_3" />
            <Button Width="130" x:Name="Savebtn" Click="Button_Click" IsEnabled="{Binding IsChanged}">
                Сохранить изменения
            </Button>
        </StackPanel>
        <DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"  CellEditEnding="taleDataGrid_CellEditEnding" EnableRowVirtualization="True" Grid.Row="3"  HorizontalAlignment="Stretch" ItemsSource="{Binding}"  Name="taleDataGrid"  VerticalAlignment="Stretch" >
            <DataGrid.Columns>
                <DataGridTextColumn Width="150*" x:Name="nameColumn" Binding="{Binding Path=Name}" Header="Название"  />
                <DataGridComboBoxColumn Width="100*" x:Name="authorIdColumn"  DisplayMemberPath="Name" SelectedValuePath="AuthorId" SelectedValueBinding="{Binding Path=AuthorId,Mode=TwoWay}" Header="Автор" />
                <DataGridComboBoxColumn  Width="100*" DisplayMemberPath="Name" SelectedValuePath="IdKey" SelectedValueBinding="{Binding Path=GroupId,Mode=TwoWay}" x:Name="groupIdColumn"  Header="Ключевое слово"  />
                <DataGridTextColumn Width="50" x:Name="yearColumn" Binding="{Binding Path=Year}" Header="Год"  />
                <DataGridTextColumn Width="100" x:Name="printingColumn" Binding="{Binding Path=Printing}" Header="Тираж"  />
                <DataGridTextColumn x:Name="commentColumn" Binding="{Binding Path=Comment}" Header="Comment" Width="SizeToHeader" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
